<template>
    <div class="container">
        <van-nav-bar
                :fixed="true"
                :title="title"
                left-arrow
                @click-left="$router.goBack()"
        ></van-nav-bar>
        <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
            <express-order-cell v-for="(item,index) in list" :item="item"
                                v-bind:key="`express-order-cell-${index}`"></express-order-cell>
        </van-pull-refresh>
    </div>
</template>

<script>
    /* eslint-disable no-console */

    import ExpressOrderCell from "../components/ExpressOrderCell";
    import api from '../net/api';
    import url from '../net/url';

    export default {
        name: "MyExpress",
        components: {ExpressOrderCell},
        data() {
            return {
                title: "我的物流",
                list: [],
                isLoading: false
            }
        },
        beforeRouteEnter(to, from, next) {
            next(vm => {
                vm.$toast.loading();
                setTimeout(vm.loadExpress(false), 1000)
            })
        },
        methods: {
            loadExpress(showLoading) {
                if (showLoading) {
                    this.isLoading = true;
                }
                api.post(url.LOAD_EXPRESS_LIST).then(res => {
                    console.log(res)
                    this.$toast.clear();
                    this.list = res.data
                    this.isLoading = false;
                }).catch(error => {
                    console.log(error)
                    this.$toast.clear();
                    this.isLoading = false;
                    this.$toast(error)
                })
            },
            onRefresh() {
                this.loadExpress(true);
            }
        },

    }
</script>

<style scoped lang="less">
    .container {
        padding-top: 46px;
        background: #f2f2f2;
    }

</style>